package com.pepsico.introjava.labs;

import com.pepsico.introjava.exceptions.InvalidParameterException;


public abstract class TaxEntity implements Payable, Comparable<TaxEntity>
{
	private String name;

	public TaxEntity (String name) throws InvalidParameterException
	{
		setName(name);
	}
	
	public final String getName()
	{
		return name;
	}

	public final void setName(String value) throws InvalidParameterException
	{
		if (value != null && value.matches(getNameValidationExpression()))
			name = value;
		else
			throw new InvalidParameterException ("Name", getNameValidationExpression(), value);
	}
	
	
	@Override
	public float pay()
	{
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String toString()
	{
		return name;
	}

	
	
	@Override
	public int hashCode()
	{
		return getName().hashCode();
	}

	@Override
	public boolean equals(Object obj)
	{
		if (obj == null || !(obj instanceof TaxEntity))
			return false;
		else
			return getName().equals(((TaxEntity)obj).getName());
	}

	@Override
	public int compareTo(TaxEntity other)
	{
		return getName().compareTo(other.getName());
	}

	protected abstract String getNameValidationExpression();
}

















